home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / WINDOWS / CLIPSTAC.ARJ / FINDFILE.CPP < prev    next >
C/C++ Source or Header  |  1992-03-27  |  3KB  |  83 lines

  1. // findfile.cpp RHS 7/18/91
  2.  
  3. #include<conio.h>
  4. #include"findfile.h"
  5.  
  6. FindFile::FindFile(char *filename, unsigned type)
  7.     {
  8.     notfound = (findfirst(filename,&F,type) ? TRUE : FALSE);
  9.     nomore = (strchr(filename,'*') || strchr(filename,'?')) ? FALSE : TRUE;
  10.     }
  11.  
  12. int FindFile::FindNext(void)
  13.     {
  14.     if(nomore)
  15.         return FALSE;
  16.     return !(nomore = notfound = (findnext(&F) ? TRUE : FALSE));
  17.     }
  18.  
  19. BOOL RecursiveFileFind::rff(char *dirspec, char *filespec)
  20.     {
  21.     char *q, *r, old;
  22.     int done;
  23.     BOOL retval = FALSE;
  24.  
  25.     struct ffblk findbuf;
  26.  
  27. //    r = &(Lastchar(dirspec));                   // save address of
  28.     r = &dirspec[strlen(dirspec)-1];                   // save address of
  29.     r++;                                        // NULL at end of dirspec
  30.  
  31.     if(Lastchar(dirspec) != '\\')               // add trailing backslash
  32.         strcat(dirspec,"\\");
  33.     q = &dirspec[strlen(dirspec)-1];
  34. //    q = &(Lastchar(dirspec));
  35.     q++;                                        // set pointer to end       
  36.     strcat(dirspec,filespec);                   // add filespec to dirspec     
  37.  
  38.     done = findfirst(dirspec,&findbuf,ALL_FILES);// find only files          
  39.     while(!done)
  40.         {
  41.         old = *q;                               // save off character @ q
  42.         *q = '\0';                              // stuff in a NULL
  43.         PostResults(dirspec,&findbuf);
  44.         *q = old;                               // restore character @ q
  45.         if(keycheck && kbhit())
  46.             {
  47.             if(eatkey)
  48.                 getch();
  49.             retval = TRUE;
  50.             goto terminate;
  51.             }
  52.         done = findnext(&findbuf);              // get next filename
  53.         }
  54.  
  55.     strcpy(q,"*.*");                            // work through sub-dirs    
  56.  
  57.     done = findfirst(dirspec,&findbuf,FA_DIREC);// find subdirectories      
  58.     while(!done)
  59.         {
  60.         if(findbuf.ff_name[0] != '.' && (findbuf.ff_attrib & FA_DIREC))
  61.             {
  62.             strcpy(q,findbuf.ff_name);          // set up with sub-dir name
  63.             if(retval = rff(dirspec,filespec))  // recurse into sub-dir
  64.                 goto terminate;
  65.             strcpy(q,"*.*");                    // restore dirspec
  66.             }
  67.         if(keycheck && kbhit())
  68.             {
  69.             if(eatkey)
  70.                 getch();
  71.             retval = TRUE;
  72.             goto terminate;
  73.             }
  74.          done = findnext(&findbuf);
  75.         }
  76. terminate:
  77.     *r = '\0';                                  // restore to original state
  78.     return retval;
  79.     }
  80.  
  81.  
  82.  
  83.